package com.anhry.www.safety.manage.zczb.struts.action;

import java.util.Calendar;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.anhry.www.safety.manage.enterprise.bean.TbCorpInfo;
import com.anhry.www.safety.manage.zczb.bean.TbZczbBgd;
import com.anhry.www.safety.manage.zczb.struts.base.ZczbBaseAction;
import com.anhry.www.safety.util.Loggers;
import com.anhry.www.safety.util.Util;
import com.anhry.www.safety.util.UtilMethod;

/**
 * @date:2012-10-18
 * @remark:历史上报管理
 * @author:dongbin
 */
@Controller
@Scope("prototype")
@SuppressWarnings("unchecked")
public class HistoryAction extends ZczbBaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	/**
	 * 报告单列表，列出本年度所有上报列表
	 * @return
	 */
	public String list(){
		try {
			TbCorpInfo corp = (TbCorpInfo)this.contextPvd.getSessionAttr(Util.SESSION_CORPUSER);
			Calendar cal = Calendar.getInstance();
			int year = cal.get(Calendar.YEAR);
			StringBuilder hql = new StringBuilder("from TbZczbHzd t where 1=1 and t.hzdStatus=1 and t.corpId="+corp.getId());
//			StringBuilder hql = new StringBuilder("from TbZczbHzd t where 1=1 and t.corpId="+corp.getId());
			if(null!=this.cYear && this.cYear.length()>0){
				hql.append(" and t.hzdYear="+this.cYear);
			}else{
				hql.append(" and t.hzdYear="+year);
				this.setCYear(String.valueOf(year));
			}
			hql.append("order by t.hzdMonth");
			this.setObjList((List)this.utilService.getHqlQuery(hql.toString()));
			this.setYearList(UtilMethod.getYearList(2012));
			this.setResult("history_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("HistoryAction list() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 报告单列表
	 * @return
	 */
	public String bgdList(){
		try {
			if(null!=this.hzdId && this.hzdId.length()>0){
				this.setObjList((List)this.utilService.getHqlQuery("from TbZczbBgd t where 1=1 and t.hzdId="+this.hzdId+" order by t.bgdNum"));
				this.setResult("history_bgd_list");
				return SUCCESS;
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("HistoryAction bgdList() 异常："+e.getMessage());
		}
		this.setTip("数据不存在！");
		return ERROR;
	}
	
	/**
	 * 隐患页面
	 * @return
	 */
	public String yhIframe(){
		try {
			if(null!=this.bgdId && this.bgdId.length()>0){
				TbZczbBgd bgd = (TbZczbBgd)this.utilService.getObjectById(TbZczbBgd.class, Long.parseLong(this.bgdId));
				if(null!=bgd){
					this.setBgd(bgd);
					this.setItemXml(this.zczbService.getItemXml(this.hzdId,this.bgdId,this.cType1,this.cZg));
					this.setResult("history_yh_iframe");
					return SUCCESS;
				}
				this.setObjList((List)this.utilService.getHqlQuery("from TbZczbYhAllView t where 1=1 and t.bgdId="+this.bgdId+" order by t.yhInfoId"));
				
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("HistoryAction yhList() 异常："+e.getMessage());
		}
		this.setTip("数据不存在！");
		return ERROR;
	}
	
	/**
	 * 隐患列表
	 * @return
	 */
	public String yhList(){
		try {
			if(null!=this.bgdId && this.bgdId.length()>0){
				this.setObjList(this.zczbService.getYhList(null, this.hzdId, this.bgdId, this.cType, this.cType1, this.cZg));
				this.setResult("history_yh_list");
				return SUCCESS;
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("HistoryAction yhList() 异常："+e.getMessage());
		}
		this.setTip("数据不存在！");
		return ERROR;
	}

}
